***************************************************************************************************************
* fig_eduageyear.do
* outcome is share of people in the cohort who are college grads, in each year and at each age.
*
* Edit: 
* 4/10/18, JR: Reorganized to use same code for BA as for some college
* 4/16/18, JR: Minor edits to fix recession shading issue.
* 01/20/2020: NG:  Update to match with the new cohort and birthcohort variables 
*************************************************************************************************************** 

clear
cap project, doinfo
*cap err
if _rc==0 {
	local pdir "`r(pdir)'"						  	    // the project's main dir.
	local dofile "`r(dofile)'"						    // do-file's stub name
	local sig {bind:{hi:[`dofile'.dta. RP : `dofile'.do, `c(current_date)']}}	// a signature in notes
	local doasproject=1
}
else {
	local pdir "~/GRscarring"
	local dofile "fig_eduageyear"
	local doasproject=0
}

set more off
local rootdir "`pdir'"
local thisdir "`pdir'" 

local scratch "`pdir'/scratch"
local rawdata "`pdir'/rawdata"
local output "`pdir'/results"

if `doasproject'==1 {
	project, uses("`scratch'/combinecollapse_yc.dta")
}

set scheme s1color

use `scratch'/combinecollapse_yc, clear


keep if age>=22 & age<=40 
isid birthcohort year 
*drop if year>=2018

gen year22=birthcohort+22
*Group adjacent cohorts
gen year22_even=floor(year22/2)*2
keep if year22==year22_even   

gen collegegrad=ed_ba + ed_grad
gen collegesome=ed_scol + ed_ba + ed_grad
replace collegesome=0 if collegesome==.
collapse (mean) collegegrad collegesome (min) age [aw=bigcpswgt], by(year22_even year)
replace collegegrad=collegegrad*100 
replace collegesome=collegesome*100 

forvalues y=1980(2)2016 {
  gen ba_cohort`y'=collegegrad if year22_even==`y'
  gen sc_cohort`y'=collegesome if year22_even==`y'
}


twoway line  ba_cohort* year if age<=30, lstyle(p1 p2 p3 p4 p1 p2 p3 p4 p1 p2 p3 p4 p1 p2 p3 p4 p1 p2 p3) ///
                                         lcolor(gray gray gray gray gray gray gray gray gray gray gray gray gray gray gray gray gray gray gray) ///
                                         lpattern(shortdash shortdash shortdash shortdash shortdash shortdash shortdash shortdash shortdash shortdash shortdash shortdash shortdash shortdash shortdash shortdash shortdash shortdash shortdash )|| ///
scatter collegegrad year if age==30 & year22_even>=1980, mstyle(p1 ) lstyle(p1) ///
        msize(small) connect(l) || ///
scatter collegegrad year if age==24 & year22_even>=1980, mstyle(p2) lstyle(p2) ///
        msize(small) msymbol(Th)  connect(l)  || ///
scatter collegegrad year if age==22 & year22_even>=1980, mstyle(p3) lstyle(p3) ///
         msymbol(X) connect(l) || ///
  , legend(order(22 "Age 22"  21 "Age 24" 20 "Age 30") cols(3)) ///
    xtitle("Year") ytitle("Percent with BA") ///
    saving("`output'/`dofile'_college.gph", replace)

twoway line  sc_cohort* year if age<=30, lstyle(p1 p2 p3 p4 p1 p2 p3 p4 p1 p2 p3 p4 p1 p2 p3 p4 p1 p2 p3) ///
                                         lcolor(gray gray gray gray gray gray gray gray gray gray gray gray gray gray gray gray gray gray gray) ///
                                         lpattern(shortdash shortdash shortdash shortdash shortdash shortdash shortdash shortdash shortdash shortdash shortdash shortdash shortdash shortdash shortdash shortdash shortdash shortdash shortdash )|| ///
scatter collegesome year if age==30 & year22_even>=1980, mstyle(p1 ) lstyle(p1) ///
        msize(small) connect(l) || ///
scatter collegesome year if age==24 & year22_even>=1980, mstyle(p2) lstyle(p2) ///
        msize(small) msymbol(Th)  connect(l)  || ///
scatter collegesome year if age==22 & year22_even>=1980, mstyle(p3) lstyle(p3) ///
         msymbol(X) connect(l) || ///
  , legend(order(22 "Age 22"  21 "Age 24" 20 "Age 30") cols(3)) ///
    xtitle("Year") ytitle("Percent with some college") ///
    saving("`output'/`dofile'_somecollege.gph", replace)


if `doasproject'==1 {
	project, creates(`output'/`dofile'_college.gph)
	project, creates(`output'/`dofile'_somecollege.gph)
}
 



